#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int a[1000],n;
int main(){
	ios::sync_with_stdio(false);
	freopen("test.txt","w",stdout);
	cin>>n;
	for(int i=0;i<n;i++)a[i]=i+1;
	do{
		for(int i=0;i<n;i++)cout<<a[i]<<" ";
		cout<<"\n";
	}while(next_permutation(a,a+n));
	return 0;
} 
